config: add support for defining interfaces via procd data
authorFelix Fietkau <[email protected]>
Tue, 12 Aug 2025 13:40:33 +0000 (15:40 +0200)
committerFelix Fietkau <[email protected]>
Tue, 12 Aug 2025 18:14:05 +0000 (20:14 +0200)
Uses the data type 'network-interface'

Signed-off-by: Felix Fietkau <[email protected]>
config.c

index 3acfd9b2334066db6c4b354bdc0e2c2323cb462b..0492bf6c1360e84a8f9fc34c8849f7310f1029ff 100644 (file)
--- a/config.c
+++ b/config.c
@@ -37,6 +37,7 @@ static struct uci_package *uci_network;
 static struct blob_attr *board_netdevs;
 static struct blob_buf b;
 static LIST_HEAD(config_vlans);
+static LIST_HEAD(config_ifaces);
 
 struct vlan_config_entry {
        struct list_head list;
@@ -566,9 +567,30 @@ config_init_package(const char *config)
        return p;
 }
 
+static void
+config_procd_interface_cb(struct blob_attr *data)
+{
+       struct interface *iface;
+       const char *name = blobmsg_name(data);
+
+       iface = interface_alloc(name, data, false);
+       if (!iface)
+               return;
+
+       data = blob_memdup(data);
+       if (!data) {
+               interface_free(iface);
+               return;
+       }
+
+       iface->config = data;
+       list_add(&iface->node.avl.list, &config_ifaces);
+}
+
 static void
 config_init_interfaces(void)
 {
+       struct interface *iface;
        struct uci_element *e;
 
        uci_foreach_element(&uci_network->sections, e) {
@@ -584,6 +606,15 @@ config_init_interfaces(void)
                if (!strcmp(s->type, "alias"))
                        config_parse_interface(s, true);
        }
+
+       netifd_ubus_get_procd_data("network-interface", config_procd_interface_cb);
+       while (!list_empty(&config_ifaces)) {
+               iface = list_first_entry(&config_ifaces, struct interface, node.avl.list);
+               list_del(&iface->node.avl.list);
+
+               if (!interface_add(iface, iface->config))
+                       interface_free(iface);
+       }
 }
 
 static void